package model

import (
	"gorm.io/gorm"
	__ "video-srv/basic/proto/rpc"
)

type DanMu struct {
	gorm.Model
	UserId    int    `gorm:"type:int" json:"userId"`
	VideoId   int    `gorm:"type:int" json:"videoId"`
	EpisodeId int    `gorm:"type:int" json:"episodeId"`
	Duration  int    `gorm:"type:int" json:"duration"`
	Content   string `gorm:"type:varchar(30)" json:"content"`
	Color     string `gorm:"type:varchar(30)" json:"color"`
}

func (d *DanMu) AddDanMu(db *gorm.DB) error {
	return db.Create(&d).Error
}

func (d *DanMu) GetDanMu(db *gorm.DB, userId, videoId, episodeId, duration int) (list []*__.DanMuList, err error) {
	err = db.Model(&d).Select("content,color").
		Where("user_id = ? and video_id = ? and episode_id = ? and duration = ?",
			userId, videoId, episodeId, duration).First(&list).Error
	return
}
